#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

// 220. 存在重复元素 III
// https://leetcode.cn/problems/contains-duplicate-iii/description/

class Solution
{
public:
    bool containsNearbyAlmostDuplicate(vector<int> &nums, int indexDiff, int valueDiff)
    {
        set<int> recordNum;
        int n = nums.size();
        for (int i = 0; i < n; i++){
            int curNum = nums[i];
            auto it = recordNum.lower_bound(curNum - valueDiff);
            if(it != recordNum.end() &&  abs(curNum - *it) <= valueDiff){
                return true;
            }
            recordNum.insert(curNum);
            if(i >= indexDiff){
                recordNum.erase(nums[i - indexDiff]);
            }
        }
        return false;
    }
};

int main()
{
    return 0;
}